package com.itheima.sc.impl.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.sc.api.sms.SmsCouponProductCategoryRelationApi;
import com.itheima.sc.mapper.sms.SmsCouponProductCategoryRelationMapper;
import com.itheima.sc.pojo.sms.CouponProductCategoryRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsCouponProductCategoryRelationImpl implements SmsCouponProductCategoryRelationApi {

    @Autowired
    private SmsCouponProductCategoryRelationMapper categoryRelationMapper;

    //添加分类关系表
    public void addProductCategoryRelation(CouponProductCategoryRelation productCategoryRelation) {
            categoryRelationMapper.insert(productCategoryRelation);
    }

    //根据CouponId删除商品分类关心数据
    public void deleteCategoryRelationByCouponId(Long id) {
        LambdaQueryWrapper<CouponProductCategoryRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(id != null, CouponProductCategoryRelation::getCouponId, id);
        categoryRelationMapper.delete(wrapper);
    }


   /* public void updateProductCategoryRelation(List<CouponProductCategoryRelation> productCategoryRelations) {
        for (CouponProductCategoryRelation productCategoryRelation : productCategoryRelations) {
            categoryRelationMapper.updateById(productCategoryRelation);
        }
    }*/

    //根据CouponId查询商品分类关心数据
    public List<CouponProductCategoryRelation> selectCategoryRelationByCouponId(Long id) {
        LambdaQueryWrapper<CouponProductCategoryRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(id != null, CouponProductCategoryRelation::getCouponId, id);
        return categoryRelationMapper.selectList(wrapper);
    }

    //删除分类关系表
    public void delectProductCategoryRelation(List<CouponProductCategoryRelation> productCategoryRelations) {
        categoryRelationMapper.deleteBatchIds(productCategoryRelations);
    }
}
